﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using PersonaLibrary.Data;
using PersonaLibrary.View;

namespace PersonaLibrary.Commands.EditCommands
{
	internal sealed class DeletePhotoCommand : CommandBase
	{
		public override bool CanExecute(object parameter)
		{
			return parameter is int;
		}

		public override void Execute(object parameter)
		{
			LinqToDbDataContext context = new LinqToDbDataContext();
			Employee employee = context.Employees.FirstOrDefault(x => ((Employee)x).Id == (int)parameter);

			if (employee == null)
				throw new Exception(string.Format("Can't load employe with {0} id", parameter));

			DeleteView dViewv = new DeleteView
			                    	{
			                    		WindowStartupLocation = WindowStartupLocation.CenterOwner
			                    	};
			if (dViewv.ShowDialog() == true)
			{
				employee.Foto = null;

				context.SubmitChanges();
				base.Execute(parameter);
			}
		}
	}
}
